# define _CRT_SECURE_NO_WARNINGS . 0
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<assert.h>
using namespace std;
int main() 
{
    FILE* file = fopen("WeCahtTest.txt", "w");
    if (file == NULL)assert(0);
    for (int i = 0; i < 50000; i++)
    {
        fprintf(file, "a");
        if (i % 10 == 0)fprintf(file, "\n");
    }
    cout << "success" << endl;
}
#if 0
# Write your MySQL query statement below
select
s1.score, (select count(distinct s2.score) from scores s2 where s2.score >= s1.score) as 'rank'
from scores s1
order by s1.score desc;

select emp_no from employees where emp_no not in(select emp_no from dept_manager);
select emp_no from employees where emp_no not in(select emp_no from dept_manager);
class Solution {
public:
    bool validPalindrome(string s) {
        int left = 0, right = s.size() - 1;
        while (left < right) {
            if (s[left] != s[right]) {
                return validPalindrome(s, left + 1, right) || validPalindrome(s, left, right - 1);
            }
            left++, right--;
        }
        return true;
    }
    bool validPalindrome(string& s, int left, int right) {
        while (left < right) {
            if (s[left] != s[right])return false;
            left++, right--;
        }
        return true;
    }

};
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
declare M int;
set M = N - 1;
RETURN(
    # Write your MySQL query statement below.
    select distinct salary from Employee order by salary desc limit 1 offset M
);
END
# Write your MySQL query statement below
select name, population, area from World where area >= 3000000 or population >= 25000000;
select* from employees where hire_date = (select distinct hire_date from employees order by
    hire_date desc limit 1 offset 2);
insert into actor values
(1, 'PENELOPE', 'GUINESS', '2006-02-15 12:34:33'),
(2, 'NICK', 'WAHLBERG', '2006-02-15 12:34:33');
insert into actor values
(1, 'PENELOPE', 'GUINESS', '2006-02-15 12:34:33'),
(2, 'NICK', 'WAHLBERG', '2006-02-15 12:34:33');
class Solution {
public:
    int numJewelsInStones(string jewels, string stones) {
        int ret = 0;
        int arr1[26] = { 0 };
        int arr2[26] = { 0 };
        for (auto c : jewels) {
            if (islower(c))
                arr2[c - 'a']++;
            else
                arr1[c - 'A']++;
        }
        for (auto c : stones) {
            if (islower(c)) {
                if (arr2[c - 'a'] != 0)ret++;
            }
            else if (arr1[c - 'A'] != 0)ret++;
        }
        return ret;
    }
};
void randomFill()
{
    srand(time(0));
    char name[52] = { 0 };
    int gender[2] = { 1,2 };
    int class_id[3] = { 1,2,3 };
    for (char i = 'A'; i <= 'Z'; i++) {
        name[i - 'A'] = i;
    }
    for (char i = 'a'; i <= 'z'; i++) {
        name[i - 'a' + 26] = i;
    }

    FILE* file = fopen("student_grades_data.text", "w");


    for (int i = 0; i < 60000; i++) {

        fprintf(file, "(%d,'",i + 1);
        string s;
        int j = 4;
        while (j--)s += name[rand() % 52];
        fprintf(file, "%s',%d,", s.c_str(), gender[rand() % 2]);
        fprintf(file,"%d,%d,%d,%d),\n", class_id[rand() % 3], rand() % 101, rand() % 101, rand() % 101);
    }
    fclose(file);
}
int main()
{
    randomFill();
    return 0;
}

class Solution {
public:
    int dx[4] = { 0,0,1,-1 };
    int dy[4] = { 1,-1,0,0 };
    vector<vector<int>> highestPeak(vector<vector<int>>& isWater) {
        int m = isWater.size();
        int n = isWater[0].size();
        vector<vector<int>>mark(m, vector<int>(n, -1));
        queue<pair<int, int>>q;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (isWater[i][j] == 1) {
                    q.push({ i,j });
                    mark[i][j] = 0;
                }
            }
        }
        while (q.size()) {
            for (int i = q.size(); i > 0; i--) {
                auto [a, b] = q.front();
                q.pop();
                for (int j = 0; j < 4; j++) {
                    int x = dx[j] + a;
                    int y = dy[j] + b;
                    if (x >= 0 && y >= 0 && x < m && y < n && mark[x][y] == -1) {
                        mark[x][y] = mark[a][b] + 1;
                        q.push({ x,y });
                    }
                }
            }
        }
        return mark;
    }
};
class Solution {
public:
    bool mark[500][500] = { 0 };
    int m, n;
    int dx[4] = { 1,-1,0,0 };
    int dy[4] = { 0,0,1,-1 };

    int bfs(vector<vector<int>>& grid, int a, int b) {
        int ret = 0;
        queue<pair<int, int>>q;
        q.push({ a,b });
        mark[a][b] = true;
        while (q.size()) {
            ret++;
            auto [k, l] = q.front();
            q.pop();
            for (int j = 0; j < 4; j++) {
                int x = dx[j] + k;
                int y = dy[j] + l;
                if (x >= 0 && x < m && y >= 0 && y < n && !mark[x][y] && grid[x][y]) {
                    mark[x][y] = true;
                    q.push({ x,y });
                }
            }
        }
        return ret;
    }


    int numEnclaves(vector<vector<int>>& grid) {
        m = grid.size();
        n = grid[0].size();
        int ret = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if ((i == 0 || j == 0 || i == m - 1 || j == n - 1) && grid[i][j] && !mark[i][j])
                    bfs(grid, i, j);
            }
        }
        for (int i = 1; i < m - 1; i++) {
            for (int j = 1; j < n - 1; j++) {
                if (grid[i][j] && !mark[i][j]) {
                    ret += bfs(grid, i, j);
                }
            }
        }
        return ret;
    }

};
class Solution {
public:
    int dx[4] = { 1,-1,0,0 };
    int dy[4] = { 0,0,1,-1 };
    int m, n;
    vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {
        m = mat.size();
        n = mat[0].size();
        vector<vector<int>>distance(m, vector<int>(n, -1));
        queue<pair<int, int>>q;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (!mat[i][j]) {
                    distance[i][j] = 0;
                    q.push({ i,j });
                }
            }
        }
        while (q.size()) {
            for (int i = q.size(); i > 0; i--) {
                auto [a, b] = q.front();
                q.pop();
                for (int j = 0; j < 4; j++) {
                    int x = dx[j] + a;
                    int y = dy[j] + b;
                    if (x < m && x >= 0 && y < n && y >= 0 && distance[x][y] == -1) {
                        distance[x][y] = distance[a][b] + 1;
                        q.push({ x,y });
                    }
                }
            }
        }
        return distance;

    }
};
int main()
{
	int arr[12][12] = { 0 };
	for (auto el : arr)
		cout << el << ' ';
	cout << endl;
}
class Solution {
public:
    int m ,n;
    bool mark[52][52] = {0};
    int dx[4] = {0,0,-1,1};
    int dy[4] = {-1,1,0,0};
    int bfs(vector<vector<int>>& forest,int a,int b,int ex,int ey){
        if(ex == a && ey == b)return 0;
        memset(mark,0,sizeof(mark));
        mark[a][b] = true;
        queue<pair<int,int>>q;
        q.push({a,b});
        int ret = 0;
        while(q.size()){
            ret++;
            for(int i = q.size() ;i > 0;i--){
                auto [k,l] = q.front();
                q.pop();
                for(int j = 0;j < 4;j++){
                    int x = k + dx[j];
                    int y = l + dy[j];
                    if(x >= 0 && x < m && y < n && y >= 0 && !mark[x][y] && forest[x][y]){
                        if(x == ex && y == ey)return ret;
                        mark[x][y] = true;
                        q.push({x,y});
                    }
                }
            }
        }
        return -1;
    }

    int cutOffTree(vector<vector<int>>& forest) {
        m = forest.size();
        n = forest[0].size();
        vector<pair<int,int>>base;
        for(int i = 0;i < m;i++)
            for(int j = 0;j < n;j++)
                if(forest[i][j] > 1)
                    base.push_back({i,j});
        sort(base.begin(),base.end(),[&](const pair<int,int>& p1,const pair<int,int>& p2){
            return forest[p1.first][p1.second] < forest[p2.first][p2.second];
        });
        int bx = 0,by = 0;
        int ret = 0;
        for(auto& [a,b] : base){
            int tmp = bfs(forest,bx,by,a,b);
            if(tmp == -1)return -1;
            ret += tmp;
            bx = a,by = b;
        }
        return ret;
    }
};
class Solution {
public:
	vector<int> searchRange(vector<int>& nums, int target) {
		vector<int>ret{ -1,-1 };
		if (nums.size() == 0)return ret;
		int left = 0, right = nums.size() - 1;
		while (left != right) {
			int mid = (left + right) / 2;
			if (nums[mid] < target)left = mid + 1;
			else right = mid;
		}
		if (nums[left] == target)ret[0] = left;
		left = 0, right = nums.size() - 1;
		while (left != right) {
			int mid = (left + right + ) / 2;
			if (nums[mid] <= target)left = mid;
			else if (nums[mid] > target)right = mid - 1;
		}
		if (nums[right] == target)ret[1] = right;
		return ret;
	}
};
class Solution {
public:
	bool CheckPermutation(string s1, string s2) {
		int hash1[26] = { 0 };
		for (auto c : s1)hash1[c - 'a']++;
		int hash2[26] = { 0 };
		for (auto c : s2)hash2[c - 'a']++;
		for (int i = 0; i < 26; i++)
			if (hash1[i] != hash2[i])
				return false;
		return true;

	}
};


#endif // 0

